<!DOCTYPE html>
<html>
<title>js原生实现for循环渲染数组 </title>
<head>
<style type="text/css">
#wrapper {
    background-color: pink;
}
#wrapper .row {
    border: 1px solid #000;
}
.row div{
    border: 1px solid #000;
    display: inline;
}
</style>        
</head>
<body>
    <div id="wrapper"></div>
</body>
<script>
function doJsFor() {
    var checkedArray = [0,2];// 选中的数组下标
    var someArray = [
            {name:'dream',value:0},
            {name:'prescription',value:1},
            {name:'tribe',value:2},
            {name:'tribe',value:2},
            {name:'tribe',value:2},
        ]
    var elementArray = [];
    for(let i=0;i<someArray.length; i++){
        var isChecked = false
        var isChecked = ''
        for(let j=0;j<checkedArray.length; j++){
            if(someArray[i].value=== checkedArray[j]) { // 数组的value等于选中数组的值,则选中复选框
                isChecked = true
            }
        }
        str = `<div class="row" ><div><input type="checkbox" ${isChecked?'checked':''} name="vehicle" value="${someArray[i].value}" /></div> <span>${someArray[i].name}</span> </div>`;
        elementArray.push(str)
    }
    document.getElementById("wrapper").innerHTML = elementArray.join('')
}
doJsFor();
</script>
</html>